package edu.cmu.cs.erl.unitTests;

import java.util.List;

import jp.ac.kobe_u.cs.prolog.lang.JavaObjectTerm;
import jp.ac.kobe_u.cs.prolog.lang.Term;

import org.junit.Assert;
import org.junit.Test;

import edu.cmu.cs.erl.ERL;
import edu.cmu.cs.erl.ERLError;
import edu.cmu.cs.erl.ERLException;
import edu.cmu.cs.erl.Oracle;
import edu.cmu.cs.erl.TermBuilder;


public class OrTest {
	
	@Test
	public void trueTest() {
		try {
			Oracle oracle = new TestOracle();
			Term orTerm = TermBuilder.createOrTerm(TermBuilder.createAtomicTerm("a"), TermBuilder.createAtomicTerm("a"));
			
			List<ERLError> errors = ERL.runPredicate(oracle, orTerm, true);
			
			Assert.assertTrue(errors.isEmpty());
		}
		catch (ERLException e) {
			e.printStackTrace();
			Assert.assertTrue(false);
		}
	}	
	
	@Test
	public void trueTest2() {
		try {
			Oracle oracle = new TestOracle();
			Term orTerm = TermBuilder.createOrTerm(TermBuilder.createAtomicTerm("a"), TermBuilder.createAtomicTerm("b"));
			
			List<ERLError> errors = ERL.runPredicate(oracle, orTerm, true);
			
			Assert.assertTrue(errors.isEmpty());
		}
		catch (ERLException e) {
			e.printStackTrace();
			Assert.assertTrue(false);
		}
	}
	
	@Test
	public void falseTest() {
		try {
			Oracle oracle = new TestOracle();
			Term orTerm = TermBuilder.createOrTerm(TermBuilder.createAtomicTerm("b"), TermBuilder.createAtomicTerm("b"));
			
			List<ERLError> errors = ERL.runPredicate(oracle, orTerm, true);
			
			Assert.assertEquals(errors.size(), 1);
		}
		catch (ERLException e) {
			e.printStackTrace();
			Assert.assertTrue(false);
		}
	}
}